@tool
class_name AdditionalEffect_RegisterKeyActionEvent
extends AdditionalEffect

## 注册KeyAction事件回调

#region 属性
@export var key_action:GameEnum.KeyAction
@export var key_action_states:Array[GameEnum.KeyActionState]
@export var addition_effect_controllers:Array[AdditionalEffect_Controller]
var controller_component:ControllerComponent
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
## 初始化
func init(args:Dictionary = {}):
	if super(args):
		controller_component = target.get_component(ControllerComponent)
		for additional_effect:AdditionalEffect_Controller in addition_effect_controllers:
			self.args["Target"] = target
			self.args["Owner"] = controller_component.entity
			additional_effect.init(args)
		return true
	return false
## 检查能否执行添加效果，默认为true
func can_excute() -> bool:
	return super()
## 执行添加效果
func excute() -> bool:
	if super():
		if controller_component:
			controller_component.register_key_action_state_changed_event(on_key_action_state_changed)
		return true
	else:
		return false
## 取消执行的效果
func cancel_excute() -> bool:
	if super():
		if controller_component:
			controller_component.unregister_key_action_state_changed_event(on_key_action_state_changed)
		return true
	else:
		return false
#endregion
#region 公共方法
func on_key_action_state_changed(cur_key_action:GameEnum.KeyAction,cur_key_action_state:GameEnum.KeyActionState):
	if key_action != cur_key_action or cur_key_action_state not in key_action_states:
		return
	if controller_component:
		for additional_effect:AdditionalEffect_Controller in addition_effect_controllers:
			additional_effect.excute()
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _init() -> void:
	if Engine.is_editor_hint():
		resource_local_to_scene = true
#endregion
